package cn.tedu._01mvcboot01.controller;

import cn.tedu._01mvcboot01.pojo.dto.BIMDTO;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@RequestMapping("/api/")
@Controller
public class BMIController {
    //http://localhost:8080/bmi?height=1.7&weight=80
    @GetMapping("/bmi")
    @ResponseBody
    public String bmi (BIMDTO bimDTO) {
        System.out.println("计算BMI："+bimDTO);
        Double height = bimDTO.getHeight();
        Double weight = bimDTO.getWeight();
        Double bmi = weight/(height*height);

        if(bmi<18.5){
            return "太瘦了";
        }if(bmi<24){
            return "正常";
        }if(bmi<27){
            return "微胖";
        }
        return "过重";
    }

    @GetMapping("/bmi/{height}/{weight}")
    @ResponseBody
    public String bmi2(@PathVariable Double height,@PathVariable Double weight){
        Double bmi = weight/(height*height);
        if(bmi<18.5){
            return "太瘦了";
        }if(bmi<24){
            return "正常";
        }if(bmi<27){
            return "微胖";
        }
        return "过重";
    }
}
